var ShapeGraphic = function(x, y, w, h, ShapeGraphicType)
{
	this.init();
	this.x = x;
	this.y = y;
	this.width = w;
	this.height = h;
	this.ShapeGraphicType = ShapeGraphicType;
	this.type = Graphic.Shape;
	this.borderColor = Color.Black;
}

// Inherit from graphical object
ShapeGraphic.prototype = new GraphicalObject();

ShapeGraphic.prototype.init = function()
{
	GraphicalObject.prototype.init.call(this); // Call super method
}

// Sets
ShapeGraphic.prototype.setWidth = function(w)
{
	this.width = w;
}

ShapeGraphic.prototype.setHeight = function(h)
{
	this.height = h;
}

ShapeGraphic.prototype.setColor = function(c)
{
	this.color = c;
}
ShapeGraphic.prototype.setSelectedColor = function(c)
{
	this.sColor = c;
}

ShapeGraphic.prototype.setHoverColor = function(c)
{
	this.hColor = c;
}

ShapeGraphic.prototype.setBorderColor = function(c)
{
	this.borderColor = c;
}

ShapeGraphic.prototype.setDisabledColor = function(c)
{
	this.dColor = c;
}

ShapeGraphic.prototype.setDoubleClickColor = function(c)
{
	this.dblclkColor = c;
}

// Gets
ShapeGraphic.prototype.getDisabledColor = function()
{
	return this.dColor;
}

ShapeGraphic.prototype.getWidth = function()
{
	return this.width;
}

ShapeGraphic.prototype.getHeight = function()
{
	return this.height;
}

ShapeGraphic.prototype.getColor = function()
{
	return this.color;
}

ShapeGraphic.prototype.getHoverColor = function()
{
	return this.hColor;
}

ShapeGraphic.prototype.getSelectedColor = function()
{
	return this.sColor;
}

ShapeGraphic.prototype.getBorderColor = function()
{
	return this.borderColor;
}

ShapeGraphic.prototype.getDoubleClickColor = function()
{
	return this.dblclkColor;
}

ShapeGraphic.prototype.decideColor = function()
{
	if (this.stateDblClickSelected == true)
	{
		return this.dblclkColor;
	}
	
	if (this.stateHover == true && this.stateSelected == false && this.enabled == true)
	{
		return this.hColor;
	}
	
	if (this.stateSelected == true && this.enabled == true)
	{
		return this.sColor;
	}
	
	if (this.enabled == false)
	{
		return this.dColor;
	}
	

	return this.color;
}

ShapeGraphic.prototype.drawRoundedRect = function(ctx, x, y, width, height, radius)
{
	ctx.moveTo(x + radius, y);
	ctx.lineTo(x + width - radius, y);
	ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
	ctx.lineTo(x + width, y + height - radius);
	ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
	ctx.lineTo(x + radius, y + height);
	ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
	ctx.lineTo(x, y + radius);
	ctx.quadraticCurveTo(x, y, x + radius, y);
}

// Draw function
ShapeGraphic.prototype.draw = function(context)
{
	context.fillStyle = this.decideColor();
	context.beginPath();
	switch(this.ShapeGraphicType)
	{
		case Shape.Rectangle:
			if (this.borderRadius > 0)
			{
				this.drawRoundedRect(context, this.x , this.y, this.width, this.height, this.borderRadius);
			}
			else
			{
				context.rect(this.x, this.y, this.width,this.height);
			}
		break;
		
		case Shape.Circle:
			context.arc(this.x, this.y, this.radius, 0, 2 * Math.PI, false);
		break;
	}
	context.closePath();
	if (context.fillStyle != "transparent")
	{
		context.fill();
	}
	
	context.strokeStyle = this.getBorderColor();
	if (context.strokeStyle != "transparent")
	{
		context.stroke();
	}
}

ShapeGraphic.prototype.getBounds = function()
{
	return {
		x: this.x,
		y: this.y,
		width: this.width,
		height: this.height
	};
}